<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>订单管理</title>
    <link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="css/comments.css" media="all">
    <style>
        .layui-form-label{
            width: 80px;
        }
		.backIn{
			display:none;
		}
    </style>
</head>
<body>
    <div class="maincontainer">
        <div class="layui-card">
            <div class="layui-card-header layuiadmin-card-header-auto">
                <form id="queryForm" class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">订单编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="shopOrderNo" autocomplete="off" class="layui-input" placeholder="订单编号" maxlength="30">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">食堂名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="canteenName" autocomplete="off" class="layui-input" placeholder="食堂名称" maxlength="50">
                            </div>
                        </div>
						<div class="layui-inline">
						    <label class="layui-form-label">下单时间</label>
						    <div class="layui-input-inline">
						        <input type="text" class="layui-input" id="selectTime" placeholder=" - ">
						    </div>
						</div>
                        <div class="layui-inline">
                            <label class="layui-form-label">订单状态</label>
                            <div class="layui-input-inline">
                                <select name="orderStatus" lay-filter="orderStatus">
                                    <option value="">全部</option>
                                    <!-- <option value="1">待提交</option> -->
                                    <option value="4">待接单</option>
                                    <option value="5">待发货</option>
                                    <option value="8">已发货</option>
                                    <option value="9">已完成</option>
                                    <option value="10">已取消</option>
                                    <option value="3">待付款</option>
                                </select>
                            </div>
                        </div>
						<div class="layui-inline">
						    <label class="layui-form-label">是否改单</label>
						    <div class="layui-input-inline">
						        <select name="updateOrderStatus" lay-filter="updateOrderStatus">
						            <option value=""></option>
						            <option value="1">是</option>
						            <option value="0">否</option>
						        </select>
						    </div>
						</div>
						<div class="layui-inline">
						    <button type="button" class="layui-btn"  lay-submit lay-filter="searchBth">查询</button>
						    <button type="reset" class="layui-btn layui-btn-primary reReset" >重置</button>
							<button type="button" class="layui-btn backIn" onclick="window.history.back();">返回</button>
						</div>
					</div>
                </form>
            </div>
            <div class="layui-card-body">
                <table class="layui-hide" id="selectTable" lay-filter="selectTable"></table>
            </div>
        </div>

    </div>
</body>

<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container toolbarDemo">
		<button class="layui-btn layui-btn-primary layui-btn-sm" lay-event="export">导出</button>
	</div>
</script>
<script type="text/javascript" src="plugins/layui/layui.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
    layui.config({
        base: 'plugins/layui/modules/',
    }).use(['http', 'table', 'form', 'laydate'], function() {
        var http = layui.http,
            table = layui.table,
            form = layui.form,
            laydate = layui.laydate;
			
			$('.reReset').click();
			
        http.checking(function() {	
            var canteenId = http.getPid('canteenId')
            var startTime = http.getPid('startTime')
            var endTime = http.getPid('endTime')
            
            laydate.render({
                elem: '#selectTime'
                ,theme: '#fbaf7e'
                ,value: getVat()
                ,range: "-"
            });
            
            function getVat(){
                var val = ''
                if(startTime && endTime){
                    val = startTime+' - '+endTime;
                }
                return val
            }
            
            var param = {};
            
            if(canteenId){
                $('.backIn').show();
                param.canteenId = canteenId;
                param.startTime = startTime;
                param.endTime = endTime;
            }else{
                $('.backIn').hide();
            }
            

            var selectTable;
            selectTable = http.table({
                elem: '#selectTable',
                url: 'food/manager/shop/order/listPage',
                method: 'get',
                id: 'selectTable',
                where:param,
                toolbar: '#toolbarDemo',
                cols: [[
                    {title:'序号',type:'numbers'},
                    {field:'shopOrderNo', title: '订单编号', align : 'center',  width: 235,
                        templet: function(d){
                            var html = ''
                            html += '<a class="buttoncolor" href="orderInfo.html?id='+d.shopOrderNo+'">'+d.shopOrderNo+'</a>'
                            return html
                        }
                    }
                    ,{field:'canteenName', title: '食堂名称', align : 'center'}
                    ,{field:'orderTotalMoney', title: '金额', align : 'center',
						templet: function (d) {
						    return http.toPrice(d.orderTotalMoney);
						}
					}
                    ,{field:'billType', title: '结账模式', align : 'center',
                        templet: function (d) {
                            return d.billType==1?'立结':'记账';
                        }
                    }
                    ,{field:'filterUpdateOrderStatus', title: '状态', align : 'center',
                    // 过滤掉改单的订单状态 1待提交2已提交3待支付4待接单5接单8发货9收货(已完成)10已取消
                        templet: function (d) {
                            var html = ''
                            switch(d.filterUpdateOrderStatus){
                                // case 1:
                                //     html = '<span style="color: #1ABC9C">待提交</span>'
                                //     break
                                case 3:
                                    html = '<span style="color: #FF0000">待付款</span>'
                                    break
                                case 4:
                                    html = '<span style="color: #1ABC9C">待接单</span>'
                                    break
                                case 5:
                                    html = '<span style="color: #0066FF">待发货</span>'
                                    break
                                case 8:
                                    html = '<span style="color: #000000">已发货</span>'
                                    break
                                case 9:
                                    html = '<span style="color: #000000">已完成</span>'
                                    break
                                case 10:
                                    html = '<span style="color: #FF0000">已取消</span>'
                                    break
                            }
                            return html
                        }
                    }
                    ,{field:'updateStatus', title: '是否改单', align : 'center',
                        templet: function (d) {
                            return d.updateStatus==1?'是':'否';
                        }
                    }
                    ,{field:'createTime', title: '下单时间', align : 'center',width: 170}
                ]]
            });

            // //查询
            form.on('submit(searchBth)', function (data) {
                let _data = data.field;
                    param = _data;
                var startTime = $('#selectTime').val()?$('#selectTime').val().split(' - ')[0]:'';
                var endTime = $('#selectTime').val()?$('#selectTime').val().split(' - ')[1]:'';
                param.startTime = startTime;
                param.endTime = endTime;
				if(canteenId){
					param.canteenId = canteenId;
				}
                selectTable.reload({
                    page:{curr:1},
                    where: param
                })
            })

            table.on('toolbar(selectTable)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
                var data = checkStatus.data; //获取选中行数据			
                if(obj.event=='export'){ // 导出
                    param.page =  1;
                    param.limit =  10;
                    param.authentication = localStorage.getItem('xi-head-authentication');
                    let paramsArray = [];
                    Object.keys(param).forEach(key => paramsArray.push(key + '=' + param[key]))  
                    window.open(TUrl+"food/manager/shop/order/export?"+paramsArray.join('&'))
                }
            })
        })

    })

</script>
</html>